package variable

import (
	"choujiang/common/models"
	"choujiang/common/db"
	"sync"
)

var EntryBoxs map[string]model.Entry

func InitBox() error {
	var mutex sync.Mutex
	mutex.Lock() //加入内存锁保持一致性
	boxs := make([]model.Box, 0)
	err := db.MysqlEngine.Where("status=?", 1).Find(&boxs)
	EntryBoxs = make(map[string]model.Entry)
	for i := 0; i < len(boxs); i++ {
		EntryBoxs[boxs[i].GameId] = model.Entry{
			AppId:     boxs[i].AppId,
			AppSecret: boxs[i].AppSecret,
		}
	}
	mutex.Unlock() //解除锁定
	return err
}
